package com.nhom4.ADP;

import org.junit.Assert;
import org.junit.Test;

public class TestUnit {

	@Test
	public void test1() {
		System.out.println("\nTest 1");
		Fraction f1 = new Fraction(1, 2);
		Fraction f2 = new Fraction(3, 4);

		Fraction f3 = new Fraction();

		f3.plus(f1, f2);
		System.out.println("f1 + f2 = " + f3.output());
		Assert.assertEquals("10/8", f3.output());

		f3.subtract(f1, f2);
		System.out.println("f1 - f2 = " + f3.output());
		Assert.assertEquals("-2/8", f3.output());

		f3.multiply(f1, f2);
		System.out.println("f1 * f2 = " + f3.output());
		Assert.assertEquals("3/8", f3.output());

		f3.divided(f1, f2);
		System.out.println("f1 / f2 = " + f3.output());
		Assert.assertEquals("4/6", f3.output());
	}

	@Test
	public void test2() {
		System.out.println("\nTest 2");
		Fraction f1 = new Fraction(-1, 2);
		Fraction f2 = new Fraction(3, 4);

		Fraction f3 = new Fraction();

		f3.plus(f1, f2);
		System.out.println("f1 + f2 = " + f3.output());
		Assert.assertEquals("2/8", f3.output());

		f3.subtract(f1, f2);
		System.out.println("f1 - f2 = " + f3.output());
		Assert.assertEquals("-10/8", f3.output());

		f3.multiply(f1, f2);
		System.out.println("f1 * f2 = " + f3.output());
		Assert.assertEquals("-3/8", f3.output());

		f3.divided(f1, f2);
		System.out.println("f1 / f2 = " + f3.output());
		Assert.assertEquals("-4/6", f3.output());
	}

	@Test
	public void test3() {
		System.out.println("\nTest 3");
		Fraction f1 = new Fraction(-1, 2);
		Fraction f2 = new Fraction(-3, 4);

		Fraction f3 = new Fraction();

		f3.plus(f1, f2);
		System.out.println("f1 + f2 = " + f3.output());
		Assert.assertEquals("-10/8", f3.output());

		f3.subtract(f1, f2);
		System.out.println("f1 - f2 = " + f3.output());
		Assert.assertEquals("2/8", f3.output());

		f3.multiply(f1, f2);
		System.out.println("f1 * f2 = " + f3.output());
		Assert.assertEquals("3/8", f3.output());

		f3.divided(f1, f2);
		System.out.println("f1 / f2 = " + f3.output());
		Assert.assertEquals("4/6", f3.output()); // -4/-6
	}

	@Test
	public void test4() {
		System.out.println("\nTest 4");
		Fraction f1 = new Fraction(0, 2);
		Fraction f2 = new Fraction(3, 4);

		Fraction f3 = new Fraction();

		f3.plus(f1, f2);
		System.out.println("f1 + f2 = " + f3.output());
		Assert.assertEquals("6/8", f3.output());

		f3.subtract(f1, f2);
		System.out.println("f1 - f2 = " + f3.output());
		Assert.assertEquals("-3/4", f3.output()); // - 6/8

		f3.multiply(f1, f2);
		System.out.println("f1 * f2 = " + f3.output());
		Assert.assertEquals("0/8", f3.output());

		f3.divided(f1, f2);
		System.out.println("f1 / f2 = " + f3.output());
		Assert.assertEquals("0/6", f3.output());
	}

	@Test
	public void test5() {
		System.out.println("\nTest 5");
		Fraction f1 = new Fraction(0, 2);
		Fraction f2 = new Fraction(0, 4);

		Fraction f3 = new Fraction();

		f3.plus(f1, f2);
		System.out.println("f1 + f2 = " + f3.output());
		Assert.assertEquals("0/8", f3.output());

		f3.subtract(f1, f2);
		System.out.println("f1 - f2 = " + f3.output());
		Assert.assertEquals("0/8", f3.output());

		f3.multiply(f1, f2);
		System.out.println("f1 * f2 = " + f3.output());
		Assert.assertEquals("0/8", f3.output());

		f3.divided(f1, f2);
		System.out.println("f1 / f2 = " + f3.output());
		Assert.assertEquals(null, f3.output());
	}

	@Test
	public void test6() {
		System.out.println("\nTest 6");
		Fraction f1 = new Fraction(0, 2);
		Fraction f2 = new Fraction(3, 0);

		Fraction f3 = new Fraction();

		f3.plus(f1, f2);
		System.out.println("f1 + f2 = " + f3.output());
		Assert.assertEquals(null, f3.output());

		f3.subtract(f1, f2);
		System.out.println("f1 - f2 = " + f3.output());
		Assert.assertEquals(null, f3.output());

		f3.multiply(f1, f2);
		System.out.println("f1 * f2 = " + f3.output());
		Assert.assertEquals(null, f3.output());

		f3.divided(f1, f2);
		System.out.println("f1 / f2 = " + f3.output());
		Assert.assertEquals("0/6", f3.output());
	}
}
